package com.runa.monitor.platinterface.netservice.equipment.dtu.furuisi;

import com.runa.monitor.platinterface.netservice.client.ConcentratorClient;
import com.runa.monitor.platinterface.netservice.equipment.NetEqu;
import com.runa.monitor.platinterface.netservice.equipment.furuisi.FuRuiSiClientDriver;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 2024/12/5 17:55
 * zhangYB
 */
@Slf4j
@ChannelHandler.Sharable
public class FuRuiSiClientHandler extends SimpleChannelInboundHandler<FuRuiSiMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FuRuiSiMessage msg) throws Exception {
        ConcentratorClient concentratorClient = ConcentratorClient.getInstanceByChannelId(ctx.channel().id().asLongText());
        if (null == concentratorClient) {
            return;
        }
        NetEqu netEqu = concentratorClient.getNetEqu();
        if (null == netEqu) {
            netEqu = FuRuiSiClientDriver.getInstance(concentratorClient.getService());
        }
        if (null != netEqu && netEqu instanceof FuRuiSiClientDriver) {
            FuRuiSiClientDriver fuRuiSiClientDriver = (FuRuiSiClientDriver)netEqu;
            fuRuiSiClientDriver.receiveMsg(msg);
        }
    }



}
